package com.nus.fellowmark.modules.rbac.controller;

import java.util.Arrays;
import java.util.Map;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.nus.fellowmark.common.response.ServerResponseEntity;
import com.nus.fellowmark.entity.SysRoleMenuMappingEntity;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.nus.fellowmark.entity.SysRoleMenuMappingEntity;
import com.nus.fellowmark.modules.rbac.service.SysRoleMenuMappingService;
import com.nus.fellowmark.common.utils.PageUtils;



/**
 * Role-permission relationship table
 *
 * @author Chen Ruoyi
 * @email chenruoyisz@gmail.com
 * @date 2023-02-11  
 */
@RestController
@RequestMapping("sys_role_menu_mapping")
public class SysRoleMenuMappingController {
    @Autowired
    private SysRoleMenuMappingService sysRoleMenuMappingService;


    @SaCheckRole(value = {"admin", "super-admin"}, mode = SaMode.OR)
    @ApiOperation("List system roleMenuMapping")
    @RequestMapping("/list")
    public ServerResponseEntity list(@RequestParam Map<String, Object> params){
        PageUtils page = sysRoleMenuMappingService.queryPage(params);
        return ServerResponseEntity.success(page);
    }


    @SaCheckRole(value = {"admin", "super-admin"}, mode = SaMode.OR)
    @ApiOperation("select roleMenuMapping by id")
    @RequestMapping("/info/{id}")
    public ServerResponseEntity info(@PathVariable("id") Integer id){
        SysRoleMenuMappingEntity roleMenuMapping = sysRoleMenuMappingService.getById(id);

        return ServerResponseEntity.success("roleMenuMapping", roleMenuMapping);
    }

    @SaCheckRole(value = {"admin", "super-admin"}, mode = SaMode.OR)
    @ApiOperation("save roleMenuMapping")
    @RequestMapping("/save")
    public ServerResponseEntity save(@RequestBody SysRoleMenuMappingEntity roleMenuMapping){
        sysRoleMenuMappingService.save(roleMenuMapping);

        return ServerResponseEntity.success();
    }

    @SaCheckRole(value = {"admin", "super-admin"}, mode = SaMode.OR)
    @ApiOperation("update roleMenuMapping")
    @RequestMapping("/update")
    public ServerResponseEntity update(@RequestBody SysRoleMenuMappingEntity roleMenuMapping){
        sysRoleMenuMappingService.updateById(roleMenuMapping);

        return ServerResponseEntity.success();
    }

    @SaCheckRole(value = {"admin", "super-admin"}, mode = SaMode.OR)
    @ApiOperation("delete roleMenuMapping")
    @RequestMapping("/delete")
    public ServerResponseEntity delete(@RequestBody Integer[] ids){
        sysRoleMenuMappingService.removeByIds(Arrays.asList(ids));

        return ServerResponseEntity.success();
    }


}
